/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet.registration;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author HONEY
 */
@WebServlet(name = "addtocompanybean", urlPatterns = {"/addtocompanybean"})
public class addtocompanybean extends HttpServlet {

    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        //PrintWriter out = response.getWriter();
        AO.Company comp=new AO.Company();
        comp.setCname(request.getParameter("cname"));
        comp.setCaddress(request.getParameter("caddress"));
        comp.setCfield(request.getParameter("cfield"));
        comp.setCutoff(Integer.parseInt(request.getParameter("cutoff")));
        comp.setCemail(request.getParameter("cemail"));
        comp.setCcontact(request.getParameter("ccontact"));
        comp.setCusername(request.getParameter("cusername"));
        comp.setCpassword(request.getParameter("cpassword"));
        
        AO.Login login=new AO.Login(comp.getCusername(),comp.getCpassword(),"company",true);
        
        try{
            DAO.LoginDAO.save(login);
            DAO.CompanyDAO.save(comp);
            request.getSession().setAttribute("logindata", login);
        request.getSession().setAttribute("companydata", comp);
        
            response.sendRedirect("company/");
          }
        catch(Exception e){e.printStackTrace();}
    }

   
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
